<?php

include 'DBconn.php';

class BranchMasterDetails {

    public function getcompany() {
        $res = mysql_query("select serialnumber,company_name from company_header where activestatus=1") or die(mysql_error());
        $res_arr = array();
        while ($row = mysql_fetch_object($res)) {
            $res_arr[] = $row;
        }
        return $res_arr;
    }

    public function getAllBranches() {
        $result = mysql_query("select * from branch_header where activestatus=1") or die(mysql_error());
        $ret_arr = array();
        while ($row = mysql_fetch_object($result)) {
            $temp = new VoBranchMaster();
            $temp->serialnumber = (int) $row->serialnumber;
            $temp->company_serialnumber = (int) $row->company_serialnumber;
            $temp->branch_name = $row->branch_name;
            $temp->branch_code = $row->branch_code;
            $temp->branch_email = $row->branch_email;
            $temp->branch_description = $row->branch_description;
            $temp->cre_userid = (int) $row->cre_userid;
            $temp->cre_datetime = $row->cre_datetime;
            $temp->activestatus = (boolean) $row->activestatus;
            $ret_arr[] = $temp;
        }
        mysql_free_result($result);
        return $ret_arr;
    }

    public function addNewBranch($VObject) {
        $query = "insert into branch_header(company_serialnumber,branch_name,branch_code,branch_email,branch_description,cre_userid,cre_datetime,activestatus) values ('$VObject->company_serialnumber','$VObject->branch_name','$VObject->branch_code','$VObject->branch_email','$VObject->branch_description','$VObject->cre_userid','$VObject->cre_datetime',1)";
        $s = mysql_query($query) or die(mysql_error());
        if ($s == 1) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
        return $this->getAllBranches();
    }

    public function editBranchDetails($VObject) {
        $query = "update branch_header set company_serialnumber='$VObject->company_serialnumber',branch_name='$VObject->branch_name',branch_code='$VObject->branch_code',branch_email='$VObject->branch_email',branch_description='$VObject->branch_description' where serialnumber='$VObject->serialnumber'";
        $s = mysql_query($query) or die(mysql_error());
        if ($s == 1) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
         return $this->getAllBranches();
    }

    public function deleteBranchDetails($serialnumber) {
        $s = mysql_query("update branch_header set activestatus=0 where serialnumber=" . $serialnumber) or die(mysql_error());
        if ($s == 1) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
        return $serialnumber;
    }

}

class VoBranchMaster {

    var $serialnumber;
    var $company_serialnumber;
    var $branch_name;
    var $branch_code;
    var $branch_email;
    var $branch_description;
    var $cre_userid;
    var $cre_datetime;
    var $activestatus;

}

?>